class cvmfslocal::client inherits cvmfslocal {

  $cvmfs_pkgs=["cvmfs","cvmfs-config-default","cvmfs-config-ihep-default","cvmfs-config-kek"]
  package { $cvmfs_pkgs :
    ensure => installed, 
    require => Yumrepo["site"],
    notify  => Exec["cvmfs reload"]
    }
  if (!defined(Package["fuse"])) {
      package { fuse: 
        ensure => latest,
        require => Yumrepo["site"],
      }
  }

  if (!$http_proxy) {
      $default_http_proxy = "DIRECT"
  } else {
      $default_http_proxy = "${http_proxy}"
  }
  file {"/etc/cvmfs/default.local":
    owner => root, 
    group => root, 
    mode => '0644',
    content => template("cvmfslocal/default.local.erb"),
    require => Package['cvmfs'],
    notify => Exec["cvmfs reload"]
  }

  file {"/etc/cvmfs/domain.d/cern.ch.local":
    owner => root,
    group => root,
    mode => '0644',
    source     =>  "puppet:///modules/cvmfslocal/cern.ch.local",
    require => Package['cvmfs'],
  }

  file {'/etc/cvmfs/domain.d/egi.eu.local':
    ensure   => link,
    force  => true,
    target   => "/etc/cvmfs/domain.d/cern.ch.local",
  }
  file {'/etc/cvmfs/domain.d/opensciencegrid.org.local':
    ensure   => link,
    force  => true,
    target   => "/etc/cvmfs/domain.d/cern.ch.local",
  }

 # add for desy
  file {"/etc/cvmfs/domain.d/desy.de.conf":
    owner => root,
    group => root,
    mode => '0644',
    source     =>  "puppet:///modules/cvmfslocal/desy.de.conf",
    require => Package['cvmfs'],
  }
  file {"/etc/cvmfs/config.d/ilc.desy.de.conf":
    owner => root,
    group => root,
    mode => '0644',
    source     =>  "puppet:///modules/cvmfslocal/ilc.desy.de.conf",
    require => Package['cvmfs'],
  }
  file {'/etc/cvmfs/keys/desy.de/':
    ensure   => "directory",
    owner    => 0,
    group    => 0,
    mode     => '0755',
    require => Package['cvmfs'],
  }->
  file {"/etc/cvmfs/keys/desy.de/desy.de.pub":
    owner => root,
    group => root,
    mode => '0644',
    source     =>  "puppet:///modules/cvmfslocal/desy.de.pub",
    require => Package['cvmfs'],
  } 
  #add keys
  file {"/etc/cvmfs/keys/hsf.org":
    owner        =>  'root',
    group        =>  'root',
    source       =>  "puppet:///modules/${module_name}/hsf.org",
    recurse      =>   true,
    ensure       =>   directory,
    force        =>   true,
  }
  file {"/etc/cvmfs/keys/igwn.org":
    owner        =>  'root',
    group        =>  'root',
    source       =>  "puppet:///modules/${module_name}/igwn.org",
    recurse      =>   true,
    ensure       =>   directory,
    force        =>   true,
  }
  file {"/etc/cvmfs/keys/osgstorage.org":
    owner        =>  'root',
    group        =>  'root',
    source       =>  "puppet:///modules/${module_name}/osgstorage.org",
    recurse      =>   true,
    ensure       =>   directory,
    force        =>   true,
  }
  file {"/etc/cvmfs/keys/storage.igwn.org":
    owner        =>  'root',
    group        =>  'root',
    source       =>  "puppet:///modules/${module_name}/storage.igwn.org",
    recurse      =>   true,
    ensure       =>   directory,
    force        =>   true,
  }
  file {"/etc/cvmfs/domain.d/storage.igwn.org.conf":
    owner => root,
    group => root,
    mode => '0644',
    source     =>  "puppet:///modules/${module_name}/storage.igwn.org.conf",
    require => Package['cvmfs'],
  }


  # for tmpwatch disable cvmfs cache
  case $operatingsystemmajrelease {
  /7|8/: {
    file { "/etc/tmpfiles.d/cvmfs.conf":
      mode       =>  '644',
      owner      =>  'root',
      group      =>  'root',
      content    =>  "x $cache_base/*",
    }
    }
  }



  if $enable_monitor
  {
    file {"/usr/local/sbin/getcvmfsclientinfo.sh":
      owner => root,
      group => root,
      mode => '0755',
      source     =>  "puppet:///modules/cvmfslocal/getcvmfsclientinfo.sh",
      require => Package['cvmfs'],
    }
    file {"/etc/cron.d/cvmfsinfo.cron":
      owner => root,
      group => root,
      mode => '0644',
      source     =>  "puppet:///modules/cvmfslocal/cvmfsinfo.cron",
      require => Package['cvmfs'],
    }
  }



  #file { "/etc/auto.cvmfs":
  #  ensure  => file,
  #  owner   => "root",
  #  group   => "root",
  #  mode    => '0755',
  #}
  file { "/etc/cvmfs/config.d/cms.cern.ch.local":
    owner   => root,
    group   => root,
    mode    => '0755',
    source     =>  "puppet:///modules/cvmfslocal/cms.cern.ch.local",
    require => Package['cvmfs'],
    notify  => Exec["cvmfs reload"]
  }
  #file {"/etc/cvmfs/domain.d/egi.eu.conf":
  #  owner   => root,
  #  group   => root,
  #  mode    => '0644',
  #  source     =>  "puppet:///modules/cvmfs/egi.eu.conf",
  #  require => Package['cvmfs'],
  #  notify  => Exec["cvmfs reload"]
  #}
  #file {"/etc/cvmfs/keys/egi.eu.pub":
  #  owner   => root,
  #  group   => root,
  #  mode    => '0644',
  #  source     =>  "puppet:///modules/cvmfs/egi.eu.pub",
  #  require => Package['cvmfs'],
  #  notify  => Exec["cvmfs reload"]
  #}

  exec { "cvmfs reload":
      path => [ "/bin", "/usr/bin", "/sbin" ],
      command => "cvmfs_config setup && cvmfs_config reload && service autofs reload",
      timeout => 0,
      refreshonly => true,
      require => Package["cvmfs"]
  }
}
